﻿using System;
using System.Collections.Generic;
using System.Threading;
using ShpMerger;

namespace ShpMergerConsole
{
    public class FileMeger
    {
        private List<string> srcFiles;
        private string destFile;
        private DestFileWriter fileMerge;

        private void MergeByThread()
        {
            fileMerge = new DestFileWriter();
            Console.Write(OutputString.MergeStart);
            fileMerge.InitDestFile(destFile);
            foreach (string srcFile in srcFiles)
            {
                Console.Write(OutputString.Merging(srcFile, destFile));
                fileMerge.AddSrcFile(srcFile, destFile);
            }
            Console.Write(OutputString.MergeComplete);
            Performer.Merging = false;
        }

        public FileMeger()
        {
            srcFiles = new List<string>();
        }

        public void Merge(List<string> srcFiles, string destFile)
        {
            this.srcFiles = srcFiles;
            this.destFile = destFile;
            Performer.Merging = true;
            new Thread(MergeByThread).Start();
        }
    }
}
